﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Composite.Presentation.Commands;
using System.ComponentModel;
using Microsoft.Practices.Composite.Events;
using MyPrism.Infrastructure;

namespace MyPrism.Search.ViewModels
{
    public class SearchControlViewModel : INotifyPropertyChanged
    {
        private string keyword;
        private IEventAggregator eventAggregator;

        public string Keyword 
        {
            get
            {
                return this.keyword;
            }
            set
            {
                this.keyword = value;
                OnPropertyChanged("Keyword");
            }
        }
        public SearchControlViewModel(IEventAggregator eventAggregator)
        {
            this.SearchComand = new DelegateCommand<string>(OnSearch);
            this.eventAggregator = eventAggregator;
        }


        
        private void OnSearch(string keyword)
        {
            eventAggregator.GetEvent<SearchEvents>().Publish(keyword);
        }

        public ICommand SearchComand { get; private set; }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
